﻿@model YahooFinanceWatcher.Models.SymbolOptionsHistoryModel

<div class="table-responsive">
	@if (Model.Hystory.Any())
    {
		<table class="table table-bordered tablesorter">
			<thead>
				<tr>
                    <th><a href="#">Contract Name</a></th>
                    <th><a href="#">Symbol</a></th>
                    <th><a href="#">Expiration Date</a></th>

					<th><a href="#">Symbol Price</a></th>
                    <th><a href="#">Strike Price</a></th>
                    <th><a href="#">Discount</a></th>
                    
					<th><a href="#">Bid</a></th>
					<th><a href="#">Ask</a></th>
					<th><a href="#">Last</a></th>

					<th><a href="#">Volume</a></th>
                    <th><a href="#">Open Interest</a></th>
                    <th><a href="#">Implied Volatility</a></th>

                    <th><a href="#">Probability</a></th>
                    <th><a href="#">Bid Ann. Return</a></th>
					<th><a href="#">Ask Ann. Return</a></th>
                    <th><a href="#">(Bid+Ask)/2</a></th>
                    <th><a href="#">Last Ann. Return</a></th>
                    <th><a href="#">Days In Trade</a></th>

				</tr>
			</thead>
			<tbody>
				@foreach (var item in Model.Hystory)
    {
					<tr>
                        <td style="text-align:center;">@item.ContractName</td>
                        <td style="text-align:center;">@item.Symbol</td>
                        <td style="text-align:center;">@item.OptionDate.ToString("MM/dd/yyyy")</td>

						<td style="text-align:right;">@item.SymbolPrice.ToString("$#,##0.00")</td>
                        <td style="text-align:right;">@item.Strike.ToString("$#,##0.00")</td>
                        <td style="text-align:right;">@item.Discount.ToString("#,##0.00%")</td>
                        
                        <td style="text-align:right;">@item.Bid.ToString("#,##0.00")</td>
                        <td style="text-align:right;">@item.Ask.ToString("#,##0.00")</td>
                        <td style="text-align:right;">@item.Last.ToString("#,##0.00")</td>

                        <td style="text-align:right;">@item.Volume.ToString("#,##0")</td>
                        <td style="text-align:right;">@item.OpenInterest.ToString("#,##0")</td>
                        <td style="text-align:right;">@((item.ImpliedVolatility/100).ToString("#,##0.00%"))</td>

                        <td style="text-align:right;">@((item.Probability / 100).ToString("#,##0.00%"))</td>
                        
                        <td style="text-align:right;">@((item.BidAnnualReturn).ToString("#,##0.00%"))</td>
                        <td style="text-align:right;">@((item.AskAnnualReturn).ToString("#,##0.00%"))</td>
                        <td style="text-align:right;">@item.BidAsk2.ToString("#,##0.00%")</td>
                        <td style="text-align:right;">@((item.LastAnnualReturn).ToString("#,##0.00%"))</td>

                        <td style="text-align:right;">@item.DaysInTrade.ToString()</td>
					</tr>
    }
			</tbody>
		</table>
    }
 else
 {
		<p>No records found.</p>
 }
</div>

<script type="text/javascript">
    $(document).ready(function () {
        $("#divSymbolOptionsHistoryList table").tablesorter();

        //var sortRefresh = true;
        @if (!string.IsNullOrEmpty(Model.SortOrder))
        {
            <text>
            //sortRefresh = false;
            setInitSort("divSymbolOptionsHistoryList", '@(Model.SortOrder)');
            </text>
        }

        $("#divSymbolOptionsHistoryList table").on("sortEnd", function (event) {

            var oldSort = $("#SortOrder").val();
            var newSort = event.target.config.sortList.toString();
            if (oldSort != "") {
                var sortOldArr = oldSort.split(',')
                var sortNewArr = newSort.split(',')

                if (sortOldArr[0] == sortNewArr[0])
                    if (sortOldArr[1] == "0")
                        sortOldArr[1] = "1";
                    else
                        sortOldArr[1] = "0";
                else {
                    sortOldArr[0] = sortNewArr[0];
                    sortOldArr[1] = "0";
                }

                $("#SortOrder").val(sortOldArr[0] + "," + sortOldArr[1]);
            }
            else
                $("#SortOrder").val(newSort);

            RefreshList();
        });
    });

</script>
